#pragma once

#include <unistd.h>
#include <fcntl.h>
#include <iostream>

enum
{
    SOCKET_ERROR = 1,
    BIND_ERROR,
    LISTEN_ERROR,
    EPOLL_CREATE_ERROR,
    EPOLL_CTL_ERROR
};

void SetNonBlock(int fd)
{
    int n = ::fcntl(fd, F_GETFL);
    if (n < 0)
    {
        std::cout << "fcntl error" << std::endl;
        return;
    }
    ::fcntl(fd, F_SETFL, n | O_NONBLOCK);
}

std::string EventsToString(uint32_t events)
{
    std::string ret;
    if (events & EPOLLIN)
        ret += "EPOLLIN";
    if (events & EPOLLET)
        ret += "|EPOLLET";
    if (events & EPOLLOUT)
        ret += "|EPOLLOUT";
    return ret;
}